﻿
module Sustainalytics.EsgRatings {

    export class EsgRpIndicatorClusterService implements IEsgRpIndicatorClusterService {

        constructor(
            private $q: ng.IQService,
            private $http: ng.IHttpService) {
        }

        public get(theme: EsgThemeEnum): ng.IPromise<EsgRpIndicatorClusterDto[]> {
            var ctx = this;

            var def = ctx.$q.defer();

            var url = '/esgratingserv/api/v1/esgRpIndicatorCluster?theme=' + theme;
            var promise = ctx.$http.get(url).then(
                // success
                function (res: ng.IHttpPromiseCallbackArg<EsgRpIndicatorClusterDto[]>) {
                    def.resolve(res.data);
                },
                // error
                function (res: ng.IHttpPromiseCallbackArg<EsgRpIndicatorClusterDto[]>) {
                    def.reject(res);
                });

            return def.promise;
        }
    }


    export var esgRpIndicatorClusterServiceName = 'EsgRpIndicatorClusterService';

    angular.module(esgRatingsModuleName).service(esgRpIndicatorClusterServiceName, EsgRpIndicatorClusterService);
} 